<template>
  <div>
    <div class="body_bg">
      <div class="container">
        <div class="left">
          <img src="~assets/img/home/course.jpg">
        </div>
        <div class="right">
          <div class="r_title">
            <v-icon large color="#42A5F5">mdi-book-open-page-variant-outline</v-icon>
            <div class="card_title">注册新用户</div>
          </div>
          <div class="r_input">
            <!--用户名-->
            <v-text-field
                v-model="signUpMsg.username"
                label="用户名"
                placeholder="请输入..."
                filled
                rounded
                dense
                counter="15"
                maxlength="15"
                :rules="[v => !!v || '提示：不能为空！']"
            ></v-text-field>
            <!--密码-->
            <v-text-field
                v-model="signUpMsg.password"
                label="密码"
                placeholder="请输入..."
                filled
                rounded
                dense
                :type="show ? 'text' : 'password'"
                :append-icon="show ? 'mdi-eye' : 'mdi-eye-off'"
                @click:append="show = !show"
                :rules="[v => !!v || '提示：不能为空！']"
            ></v-text-field>
          </div>
          <div class="r_bt text-center">
            <v-btn
                depressed
                color="#42A5F5"
                rounded
                width="88%"
                height="40px"
                dark
                style="font-weight: bold;font-size: 16px"
                @click="signUp"
            >注册
            </v-btn>
          </div>
          <div class="r_registered">
            注册即表示您同意我们的
            <span style="color: #42A5F5">服务条款与隐私政策</span>
          </div>
          <div class="r_registered">
            已经拥有账户？
            <span style="color: #42A5F5" @click="toLogin">登录</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import {register} from "../../network/Details/common/user";

export default {

  name: "SignUp",
  data() {
    return {
      //密码显示
      show: false,
      //账号
      signUpMsg: {
        username: '',
        password: '',
      },
      //提示
      snackbarShow: false,
      snackbarText: '',
      snackbarColor: '#F44336',
    }
  },
  methods: {
    //注册
    signUp() {
      if (this.signUpMsg.username.length === 0 || this.signUpMsg.password === 0) {
        this.$message.error('用户名或密码不能为空！');
        return
      }
      //注册账号验证
      register(this.signUpMsg).then(res => {
        console.log(res)
        if (res.code === 200) {
          this.$message.success("注册成功！");
        }
      })
    },
    //跳转到注册
    toLogin() {
      this.$router.push('/login')
    },
  }
}
</script>

<style lang="less" scoped>
.body_bg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  /*background-image: linear-gradient(-225deg, #20E2D7 0%, #F9FEA5 100%);*/
}

.container {
  width: 913px;
  height: 411px;
  border-radius: 21px;
  background: #ffffff;
  box-shadow: 3px 2px 8px rgba(0, 0, 0, 0.31);
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  padding: 15px;
  display: flex;
  flex-direction: row;

  .left {
    width: 622px;
    height: 380px;

    img {
      width: 100%;
      height: 100%;
    }
  }

  .right {
    height: 365px;
    width: 340px;
    border: #F6F6F6 1px solid;
    display: flex;
    flex-direction: column;

    .r_title {
      height: 60px;
      display: flex;
      flex-direction: row;
      font-size: 18px;
      text-align: center;
      line-height: 60px;
      font-weight: bold;
      justify-content: space-evenly;
    }

    .r_input {
      margin-top: 20px;
      width: 90%;
      margin-left: 6%;

      .r_input_text {
        margin-top: 5px;
        width: 90%;
        height: 18px;
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
        margin-left: 5%;
      }
    }

    .r_bt {
      display: flex;
      justify-content: center;
      margin-top: 20px;
    }

    .r_registered {
      margin-top: 10px;
      text-align: center;
      color: #666666;
      font-size: 13px;
    }

  }
}
</style>